package com.xiaoxiong.mami.dao.mapper;

import com.xiaoxiong.mami.dao.daomain.Cart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface CartMapper {
    @Delete({
        "delete from cart",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into cart (id, userId, ",
        "goodsId, batchNumber, ",
        "total, remark, createTime, ",
        "updateTime, status, ",
        "propertyId)",
        "values (#{id,jdbcType=BIGINT}, #{userId,jdbcType=VARCHAR}, ",
        "#{goodsId,jdbcType=VARCHAR}, #{batchNumber,jdbcType=VARCHAR}, ",
        "#{total,jdbcType=INTEGER}, #{remark,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, ",
        "#{updateTime,jdbcType=TIMESTAMP}, #{status,jdbcType=VARCHAR}, ",
        "#{propertyId,jdbcType=INTEGER})"
    })
    int insert(Cart record);

    @InsertProvider(type=CartSqlProvider.class, method="insertSelective")
    int insertSelective(Cart record);

    @Select({
        "select",
        "id, userId, goodsId, batchNumber, total, remark, createTime, updateTime, status, ",
        "propertyId",
        "from cart",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="userId", property="userId", jdbcType=JdbcType.VARCHAR),
        @Result(column="goodsId", property="goodsId", jdbcType=JdbcType.VARCHAR),
        @Result(column="batchNumber", property="batchNumber", jdbcType=JdbcType.VARCHAR),
        @Result(column="total", property="total", jdbcType=JdbcType.INTEGER),
        @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
        @Result(column="createTime", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="updateTime", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="status", property="status", jdbcType=JdbcType.VARCHAR),
        @Result(column="propertyId", property="propertyId", jdbcType=JdbcType.INTEGER)
    })
    Cart selectByPrimaryKey(Long id);

    @UpdateProvider(type=CartSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Cart record);

    @Update({
        "update cart",
        "set userId = #{userId,jdbcType=VARCHAR},",
          "goodsId = #{goodsId,jdbcType=VARCHAR},",
          "batchNumber = #{batchNumber,jdbcType=VARCHAR},",
          "total = #{total,jdbcType=INTEGER},",
          "remark = #{remark,jdbcType=VARCHAR},",
          "createTime = #{createTime,jdbcType=TIMESTAMP},",
          "updateTime = #{updateTime,jdbcType=TIMESTAMP},",
          "status = #{status,jdbcType=VARCHAR},",
          "propertyId = #{propertyId,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Cart record);
}